function getTips() {
  if (!Global.LoginState.isAuthorize) {
    Global.PlatformUtils.sendLogEvent('用户未授权');
    return '请授权使用"用户信息"';
  } else if (!Global.LoginState.isLogin) {
    Global.PlatformUtils.sendLogEvent('微信未登录');
    return '微信未登录';
  } else {
    return '请重新连接';
  }
}


function checkAuthorizeCallback() {
  if (Global.LoginState.isLogin && Global.LoginState.isAuthorize) {
    return true;
  } else {
    Global.Toast.show(getTips());
    return false;
  }
}


function checkAuthorize(callback) {
  if (Global.LoginState.isLogin && Global.LoginState.isAuthorize) {
    callback(true);
  } else {
    Global.Waiting.show();
    Global.PlatformUtils.login(() => {
      Global.Waiting.hide();
      if (Global.LoginState.isLogin) {
        Global.PlatformUtils.checkAuthorize(() => {
          let ok = checkAuthorizeCallback();
          callback && callback(ok);
        });
      }
    });
  }
}


function isAuthorize() {
  return Global.LoginState.isLogin && Global.LoginState.isAuthorize;
}

module.exports = {
  checkAuthorize,
  isAuthorize
};
